var ywy="";
var jshzApp = function() {

	var mc = manager.findParamFromUrl("dxmc");

	   ywy = manager.findParamFromUrl("ywy");

	mc = "Education Bureau of XX City ";

	$("#dxmc").html(mc);

	function load() {
		var ractive = new Ractive({
			el : '#jshz-containter',
			template : "#jshz-template",
			data : {
				isContaint : function(arr, val) {
					var flag = false;
					for (var i = 0; i < arr.length; i++) {
						if (arr[i] == val) {
							flag = true;
							break;
						}
					}
					return flag;
				}
			},
			oncomplete : function() {
				getData(function(data) {
					var arr = [];
					ractive.set("o", data);
					if(data==null||data.id==null){
						//注册帐号，尚未入驻的情况
						alert("You are not a partner, please sign in first, sign an agreement!");
						return;
					}
					
					//待审核状态
					if(data.xyzt == Constants.XYZT.XYZT_DSH){
						alert("Not yet reviewed!");
						return;
						
					}
					
					//已审核-审批结果：拒绝
					if(data.xyzt == Constants.XYZT.XYZT_YSH&&data.spjg==Constants.SPJG.SPJG_JJ){
						alert("The review has been returned!");
						return;
					}
					
					if($("#content").hasClass("none")){
						$("#content").removeClass("none");
					}
					// 如果是结束合作,变成灰色
					if (data.xyzt == Constants.XYZT.XYZT_JSHZ) {
						var yyStr = data.jshzyy;
						arr = yyStr.split(",");
						$("input").attr("disabled", true);
						$("textarea").attr("disabled", true);
						$(".ad-btn-qrjshz").css("background-color", "#545454");
					}
					ractive.set("arr", arr);
				})
			}
		});
		ractive.on({
			jshz : function() {
				var o = {};
				var jsyyStr = "";
				$("input[type='checkbox']:checked").each(function() {var val = $(this).val();  jsyyStr += val + ","});
				if (jsyyStr) {
					jsyyStr = jsyyStr.substring(0, jsyyStr.length - 1);
				}else{
					alert("Termination reason can not be empty!", "Promp");return;
				}
				var jssm = ractive.get("o.jshzsm");
				if (!jssm) {alert("Termination description can not be empty!", "Promp");return}
				o.jsyy = jsyyStr;
				o.jssm = jssm;
				//提交
				confirm({txt: "Confirm to terminate the partnership?",successCallBackFun: successCallBackFun,cancelCallBackFun: cancelCallBackFun});	
				function successCallBackFun(){ jshz(o) }//确认
				function cancelCallBackFun(){}//取消
			}
		});
	}

	function getData(fn) {
		$.ajax({
			type : "get",
			url : Constants.epUrlPath + "jshz/getHzgxbList?ywy="+ywy,
			success : function(data) {
				if (data == Constants.NOLOGIN.CODE) {return}
				fn.call("", data);
			}
		});
	}

	function jshz(o) {
		$.ajax({
			url : Constants.epUrlPath + "jshz/updateJszhxx",
			type : "post",
			contentType : 'application/json;charset=UTF-8',
			dateType : "json",
			data : JSON.stringify(o),
			success : function(data) {
				if (data == Constants.NOLOGIN.CODE) {return}
				var objs3 = {txt : "Operation successful!",callBackFun : function() {location.reload()}}
				success(objs3);
			}
		})
	}

	return {
		init : function() {
			load();
		}
	}
}();
$(document).ready(jshzApp.init);
